package com.huang.manager;

import jakarta.annotation.PreDestroy;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * @author Ikaros
 * @since 2025/9/5 20:44 星期五
 */
@Component
@Slf4j
@RequiredArgsConstructor
public class ShutdownManager {

    private final AsyncManager asyncManager;

    @PreDestroy
    public void destroy() {
        shutdownAsyncManager();
    }

    /**
     * 停止异步执行任务
     */
    private void shutdownAsyncManager() {
        try {
            log.info("====关闭后台任务任务线程池====");
            asyncManager.shutdown("任务线程池");
        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }
    }

}
